package seminarski.utils;

import java.util.ArrayList;
import java.util.Random;

import common.point.PointG;

public class Utils {
	private static Random r = new Random();
	
	public static double distance(PointG<Double> p1, PointG<Double> p2){
		return Math.sqrt((p1.x() - p2.x())*(p1.x() - p2.x()) + (p1.y() - p2.y())*(p1.y() - p2.y()));
	}
	
	public static double vektorskiProizvod(PointG<Double> A, PointG<Double> B, PointG<Double> C) 
	{
		double[] AB = new double[2];
		double[] AC = new double[2];
		AB[0] = B.x() - A.x();
		AB[1] = B.y() - A.y();
		AC[0] = C.x() - A.x();
		AC[1] = C.y() - A.y();

		double cross = AB[0] * AC[1] - AB[1] * AC[0];

		return cross;
	}
	
	public static int nextInt(){
		return r.nextInt()%350;
	}
	
	public static double nextDouble(double a, double b){
		return (r.nextInt((int) (b - a)) + a) + r.nextDouble(); 
	}

	public static int getMinY(ArrayList<PointG<Double>> tacke) {
		
		if(tacke == null)
			return -1;
		
		PointG<Double> minPoint = tacke.get(0);
		int index = 0;
		for(int i = 0; i < tacke.size(); i++)
		{
			PointG<Double> point = tacke.get(i);
			if(point.y() < minPoint.y()){
				minPoint = point;
				index = i;
			}
			else if(point.y() == minPoint.y()){
				minPoint = point.x() < minPoint.x() ? point : minPoint;
				index = point.x() < minPoint.x() ? i : index;
			}
		}
		return index;
	}
}
